app.controller('AreaModalCtrl', function($scope, $modalInstance, toaster, param, ajax) {

    $scope.submitting = false;
    $scope.param = param;
    if ($scope.param.data == null) {
        $scope.param.data = {};
    }
    if ($scope.param.type == 1) {
        $scope.type = "上车";
    } else {
        $scope.type = "下车";
    }

    //获取城市
    (function() {
        ajax.call(new Req.GET({
            resource: 'city/rt/' + $scope.param.city + '/id'
        })).then(function(result) {
            $scope.city = result.result;
        }, function() { });
    })();

    //获取组织列表
    (function() {
        ajax.call(new Req.GET({
            resource: 'organization/2/list'
        })).then(function(result) {
            $scope.orglist = result.result;
        }, function() { });
    })();

    $scope.ok = function() {
        if ($scope.myForm.$valid) {
            if ($scope.orglist.selected == undefined) {
                toaster.pop('warning', '提示', '请选择单位！');
                return;
            }
            $scope.param.data.name = $scope.param.name;
            $scope.param.data.type = $scope.param.type;
            $scope.param.data.city = $scope.param.city;
            $scope.param.data.organizationId = $scope.orglist.selected.id;
            $modalInstance.close($scope.param);
        }
    };

    $scope.cancel = function() {
        $modalInstance.dismiss('cancel');
        $scope.submitting = false;
    };
});